{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "prompt-snapshot",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0, len([1,2,3])))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "desperate-lease",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/buddy-strings\n",
    "\n",
    "\n",
    "Runtime: 48 ms, faster than 13.91% of Python3 online submissions for Buddy Strings.\n",
    "Memory Usage: 14.6 MB, less than 47.81% of Python3 online submissions for Buddy Strings.\n",
    "\n",
    "\n",
    "```python\n",
    "from itertools import combinations\n",
    "\n",
    "class Solution:\n",
    "    def simplify(self, s):\n",
    "        new_s = \"\"\n",
    "        for c in s:\n",
    "            if len(new_s) >= 1:\n",
    "                if c != new_s[-1]:\n",
    "                    new_s += c\n",
    "                else:\n",
    "                    if len(new_s) >= 2:\n",
    "                        if new_s[-1] == c and new_s[-2] == c:\n",
    "                            pass\n",
    "                        else:\n",
    "                            new_s += c\n",
    "                    elif len(new_s) == 1:\n",
    "                        new_s += c\n",
    "            else:\n",
    "                new_s += c\n",
    "        return new_s\n",
    "    \n",
    "    def buddyStrings(self, a: str, b: str) -> bool:\n",
    "        #7:40\n",
    "        a = self.simplify(a)\n",
    "        b = self.simplify(b)\n",
    "        if len(a) != len(b):\n",
    "            return False\n",
    "        if set(a) != set(b):\n",
    "            return False\n",
    "        possibility = combinations(list(range(0, len(a))), 2)\n",
    "        for possible_list in possibility:\n",
    "            newA = list(a)\n",
    "            i1 = possible_list[0]\n",
    "            i2 = possible_list[1]\n",
    "            c1 = newA[i1]\n",
    "            c2 = newA[i2]\n",
    "            newA[i1] = c2\n",
    "            newA[i2] = c1\n",
    "            newA = \"\".join(newA)\n",
    "            if newA == b:\n",
    "                return True\n",
    "        return False\n",
    "        #7:58\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "simplified-wages",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
